package com.controller.sys;


import com.alibaba.fastjson.JSON;
import com.common.Result;
import com.common.log.OperationLog;
import com.common.log.OperationType;
import com.entity.sys.Department;
import com.entity.sys.PoliticsStatus;
import com.service.sys.PoliticsStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author clay
 * @since 2022-02-23
 */
@Slf4j
@Api("PoliticsStatusController")
@RestController
@RequestMapping("/politicsStatus")
public class PoliticsStatusController {

    @Resource
    private PoliticsStatusService politicsStatusService;

    @ApiOperation("添加政治面貌信息")
    @OperationLog(operationType = OperationType.INSERT, describe = "添加学部信息", entity = PoliticsStatus.class, primaryKey = "id")
    @PostMapping(value = "/add")
    public Result addDepartment(@RequestBody @Valid PoliticsStatus politicsStatus) {
        log.info("添加学部信息, {}", JSON.toJSON(politicsStatus));
        politicsStatusService.save(politicsStatus);
        return Result.success();
    }

    @ApiOperation("删除政治面貌信息")
    @OperationLog(operationType = OperationType.DELETE, describe = "删除学部", entity = PoliticsStatus.class, primaryKey = "id")
    @GetMapping(value = "/delete/{id}")
    public Result deleteDepartment(@PathVariable("id") String id) {
        politicsStatusService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("通过id获取信息")
    @GetMapping(value = "/info/{id}")
    public Result info(@PathVariable("id") String id) {
        return Result.success(politicsStatusService.getById(id));
    }

    @ApiOperation("查询政治面貌信息")
    @PostMapping(value = "/select")
    public Result selectDepartment(@RequestBody PoliticsStatus department) {
        return Result.success(politicsStatusService.select(department));
    }

    /**
     * 修改
     * @param politicsStatus
     * @return
     */
    @ApiOperation("修改政治面貌信息")
    @OperationLog(operationType = OperationType.UPDATE, describe = "修改学部信息", entity = Department.class, primaryKey = "id")
    @PostMapping(value = "/update")
    public Result updateDepartment(@RequestBody @Valid PoliticsStatus politicsStatus) {
        return Result.success(politicsStatusService.updateById(politicsStatus));
    }
}
